/**
 * date: 2015.10.02
 * version: 1.0
 * utils of i18n
 */
package tyris.util.i18n;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * utils of i18n
 * 
 * @author
 * 
 */
public class MessageResource{
    /**
     * the base name of resource bundle
     */
    private static final String BASE_NAME = "tyris.util.i18n.messages";

    /**
     * resource bundles
     */
    private static final ResourceBundle RESOURCES_CN = ResourceBundle.getBundle(BASE_NAME, Locale.SIMPLIFIED_CHINESE);
    private static final ResourceBundle RESOURCES_US = ResourceBundle.getBundle(BASE_NAME, Locale.US);
      
    /**
     * get corresponding resource from resource bundle
     * @param key
     * @param locale
     * @return
     */
    public static String getMessage(String key, Locale locale){
        if (Locale.SIMPLIFIED_CHINESE == locale)
            return RESOURCES_CN.getString(key);
        else if (Locale.US == locale)
            return RESOURCES_US.getString(key);
        else
            return key;
    }
}
